﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace CheckersUI
{
    public delegate void CellClickHandler(PictureBoxUICheckersCell i_UICheckersCell);

    public delegate void CellDoubleClickHandler(PictureBoxUICheckersCell i_UICheckersCell);
    
    public partial class PictureBoxUICheckersCell : PictureBox
    {
        public event CellClickHandler OnCellClick;

        public event CellDoubleClickHandler OnCellDoubleClick;

        private bool m_IsClicked = false;
        private char m_CellSymbol;
        private char m_CellColumn;
        private char m_CellRow;

        public PictureBoxUICheckersCell()
        {
            this.InitializeComponent();
            this.m_CellSymbol = ' ';
        }

        public char Column
        {
            get
            {
                return this.m_CellColumn;
            }

            set
            {
                this.m_CellColumn = value;
            }
        }

        public char Row
        {
            get
            {
                return this.m_CellRow;
            }

            set
            {
                this.m_CellRow = value;
            }
        }

        public char Symbol
        {
            get
            {
                return this.m_CellSymbol;
            }

            set
            {
                this.m_CellSymbol = value;
            }
        }

        public bool IsClicked
        {
            get
            {
                return this.m_IsClicked;
            }

            set
            {
                this.m_IsClicked = value;
            }
        }

        private void UICheckersCell_Click(object sender, EventArgs e)
        {
            if (!this.m_IsClicked)
            {
                this.m_IsClicked = true;
                this.BackColor = Color.Blue;
            }
            else
            {
                this.m_IsClicked = false;
                this.BackColor = Color.Orchid;
            }

            if (this.OnCellClick != null)
            {
                this.OnCellClick.Invoke(sender as PictureBoxUICheckersCell);
            }
        }

        private void PictureBoxUICheckersCell_DoubleClick(object sender, EventArgs e)
        {
            DialogResult userChoise = new DialogResult();
            userChoise = MessageBox.Show("Are you sure you want to remove this coin?", "Remove Coin", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (userChoise == DialogResult.Yes)
            {
                this.OnCellDoubleClick.Invoke(sender as PictureBoxUICheckersCell);
            }
        }
    }
}